﻿using System;
using Autofac;
using Extensions.Interceptor.Cache.Keys;

namespace Extensions.Interceptor.Cache;

public static class CacheInterceptorDependencyInjection
{
    public static ContainerBuilder AddCacheInterceptor(this ContainerBuilder builder)
    {
        ArgumentNullException.ThrowIfNull(builder);

        builder.RegisterTypes(typeof(MethodNameStrategy),
                typeof(DateTimeStrategy),
                typeof(MethodParameterStrategy),
                typeof(RetrunTypeStrategy))
            .As<BaseStrategy>();
        builder.RegisterType<MemoryCacheInterceptor>();
        // 注入本身的时候  要用asself
        builder.RegisterType<KeyContext>().AsSelf();


        return builder;
    }
}